namespace NHCodeFirst.FluentMapper
{
    using System;
    using Enums;
    using HbmModel;

    public class TypeAndColumnMapper<TChild> : ColumnMapper<TChild>
    {
        private readonly TypeE type;
        internal TypeAndColumnMapper(TypeE type, Column column) : base(column)
        {
            this.type = type;
        }


        public TChild Type(NHibernateType value)
        {
            type.Name = value.ToString();
            type.Parameters.Clear();
            return child;
        }

        public TChild Type(ClrType value)
        {
            type.Name = EnumsToHbmString.GetClrType(value);
            type.Parameters.Clear();
            return child;
        }

        public TChild Type<T>(params Param[] parameters)
        {
            return Type(typeof (T), parameters);
        }

        public TChild Type(Type value, params Param[] parameters)
        {
            type.Parameters.Clear();
            type.Name = value.FullName;
            foreach (var parameter in parameters)
                type.Parameters.Add(parameter.Name, parameter.Value);
            return child;
        }
    }
}